const request = ({pubUrl, url, method='GET', header = {}, data={}}) => {
	//development 开发 
	// production 生产/线上
	const baseUrl = pubUrl ? pubUrl : import.meta.env.MODE === 'development' ? 'http://localhost:8002':'http://localhost:8003'
	const token = uni.getStorageSync('token')
	const realHeader = token ? {...header, token} : header
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			method,
			data,
			header:realHeader,
			success(res) {
				// 接口成功
				if(res.statusCode===200) {
					resolve(res.data)
				} else if(res.statusCode === 500) {
					uni.$u.toast('服务端错误')
					reject('服务端错误')
				}
				
			},
			fail(err) {
				uni.$u.toast('服务端错误')
				reject(err)
			}
			
		})
	})
}

export default request